package com.amrit.onetomany;

import java.util.Calendar;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateMain {

	public static void main(String[] args) {

		Country1 countryIndia = new Country1("India", 50000000);

		State mpState = new State("Madhya Pradesh", 1000000, Calendar.getInstance());
		State mhState = new State("Maharastra", 2000000,Calendar.getInstance());

		countryIndia.getListOfStates().add(mpState);
		countryIndia.getListOfStates().add(mhState);

		Configuration configuration = new Configuration();
		configuration.configure();
		ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(
				configuration.getProperties()).build();
		SessionFactory sf = configuration.buildSessionFactory(sr);
		Session ss = sf.openSession();

		ss.beginTransaction();
		ss.save(countryIndia);
		ss.getTransaction().commit();
		ss.close();

	}

}